

/* This do file provides the code to generate Figure A3.4 in Appendix 3. */

global dataDir "~/Dropbox/Party_Interactions_Perceptions/PSRM Submission/Replication Files"
use "$dataDir/replication_data.dta", clear



set more off
foreach i of numlist 1 2{

replace dyad_name`i'="AfD" if dyad_name`i'=="afd"
replace dyad_name`i'="Alt" if dyad_name`i'=="alt"
replace dyad_name`i'="BQ" if dyad_name`i'=="bq"
replace dyad_name`i'="CDU" if dyad_name`i'=="cdu"
replace dyad_name`i'="Cons" if dyad_name`i'=="cons"
replace dyad_name`i'="KF" if dyad_name`i'=="cpp"
replace dyad_name`i'="DF" if dyad_name`i'=="dpp"
replace dyad_name`i'="Enh" if dyad_name`i'=="enh"
replace dyad_name`i'="FDP" if dyad_name`i'=="fdp"
replace dyad_name`i'="Lab" if dyad_name`i'=="lab"
replace dyad_name`i'="Lib" if dyad_name`i'=="lib"
replace dyad_name`i'="LibDem" if dyad_name`i'=="libdem"
replace dyad_name`i'="Linke" if dyad_name`i'=="linke"
replace dyad_name`i'="NDP" if dyad_name`i'=="ndp"
replace dyad_name`i'="NB" if dyad_name`i'=="new"
replace dyad_name`i'="RadVen" if dyad_name`i'=="rad"
replace dyad_name`i'="SDP" if dyad_name`i'=="sdp"
replace dyad_name`i'="SNP" if dyad_name`i'=="snp"
replace dyad_name`i'="SPD" if dyad_name`i'=="spd"
replace dyad_name`i'="SF" if dyad_name`i'=="spp"
replace dyad_name`i'="UKIP" if dyad_name`i'=="ukip"
replace dyad_name`i'="Ven" if dyad_name`i'=="ven"
replace dyad_name`i'="Green" if dyad_name`i'=="green"


}

capture drop dyadname
egen dyadname=concat(dyad_name1 dyad_name2), punct("-")


capture drop countryyear
egen countryyear=concat(country year)




/* UK 2017*/


set more off

local figure=1
levelsof dyadname if countryyear=="UK2017" & coop!=., local(levels) 
 foreach l of local levels {
 
sum coop if dyadname=="`l'" & countryyear=="UK2017" & coop!=.

local ll2 : di %3.2f r(mean)

 
twoway histogram coop if dyadname=="`l'" & countryyear=="UK2017" ///
 & coop!=., ///
 discrete percent xtitle("") ytitle("") color(gray) xline(`ll2') ///
 text(26 `ll2' "`ll2'") title("`l'") graphregion(margin(0 0 0 0)) plotregion(margin(0 0 0 0)) ///
 name(`ctryyear'fig`figure', replace) yscale(r(0 30)) nodraw
 
 local figure=`figure'+1
 
 }
 
 
 set more off
 capture drop partiesname
 gen partiesname=""
 
  capture drop avg
 gen avg=.
 
 local row=1
 levelsof dyadname if countryyear=="UK2017", local(levels) 
 foreach l of local levels {
 sum coop if dyadname=="`l'" & countryyear=="UK2017" & coop!=.
replace avg=r(mean) in `row'
  replace partiesname="`l'" in `row'
  local row=`row'+1

 }
 capture drop groupid
 egen groupid=group(partiesname)

graph combine fig2 fig5 fig7 fig6 fig4 fig3 fig1 fig8 , ///
 l1(% of Respondents) b1(Perceived Cooperation Scores) rows(2) ///
 note("Dashed line indicates the average cooperation score",size(vsmall)) ///
 ycommon scale(1.15) title(UK 2017)  
 
 graph export "$dataDir/figA3_4(part 1).pdf", replace

 
 /* UK 2019 */
 
 set more off

local figure=1
levelsof dyadname if countryyear=="UK2019" & coop!=., local(levels) 
 foreach l of local levels {
 
sum coop if dyadname=="`l'" & countryyear=="UK2019" & coop!=.

local ll2 : di %3.2f r(mean)

 
twoway histogram coop if dyadname=="`l'" & countryyear=="UK2019" ///
 & coop!=., ///
 discrete percent xtitle("") ytitle("") color(gray) xline(`ll2') ///
 text(28 `ll2' "`ll2'") title("`l'") graphregion(margin(0 0 0 0)) plotregion(margin(0 0 0 0)) ///
 name(`ctryyear'fig`figure', replace) yscale(r(0 30)) nodraw
 
 local figure=`figure'+1
 
 }
 
 
 set more off
 capture drop partiesname
 gen partiesname=""
 
  capture drop avg
 gen avg=.
 
 local row=1
 levelsof dyadname if countryyear=="UK2019", local(levels) 
 foreach l of local levels {
 sum coop if dyadname=="`l'" & countryyear=="UK2019" & coop!=.
replace avg=r(mean) in `row'
  replace partiesname="`l'" in `row'
  local row=`row'+1

 }
 capture drop groupid
 egen groupid=group(partiesname)

 
graph combine fig3 fig10 fig8 fig6 fig7 fig13 fig5 fig11 fig1 ///
fig4 fig12 fig14 fig9 fig15 fig2 , ///
 l1(% of Respondents) b1(Perceived Cooperation Scores) rows(3) ///
 note("Dashed line indicates the average cooperation score",size(vsmall)) ///
 ycommon scale(1.15) title(UK 2019)  
 
 graph export "$dataDir/figA3_4(part 2).pdf", replace



